home *** CD-ROM | disk | FTP | other *** search
/ Aminet 3 / Aminet 3 - July 1994.iso / Aminet / misc / emu / SetTDRetry.lha / SetTDRetry.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-04-24  |  2.5 KB  |  114 lines

  1. /*
  2. ** SetTDRetry v37.1
  3. ** 
  4. ** Compiled under SAS/C 6.50
  5. **
  6. */
  7.  
  8. #define __USE_SYSBASE
  9.  
  10. #include <exec/types.h>
  11. #include <exec/execbase.h>
  12. #include <dos/dosextens.h>
  13. #include <dos/rdargs.h>
  14. #include <devices/trackdisk.h>
  15.  
  16. #include <string.h>
  17.  
  18. #include <proto/dos.h>
  19. #include <proto/exec.h>
  20.  
  21. #define DOSLIB "dos.library"
  22. #define DOSVER 36L
  23.  
  24. #define ThisProcess ((struct Process *)(SysBase->ThisTask))
  25. #define Result2(x) ThisProcess->pr_Result2 = x
  26.  
  27. #define OPT_UNITS 0
  28. #define OPT_RETRY 1
  29. #define OPT_QUIET 2
  30. #define OPT_COUNT 3
  31.  
  32. #define TEMPLATE "UNITS=U/A/N/M,RETRYCOUNT=RC/N/K,QUIET=Q/S"
  33.  
  34. #define MSG_FAILED "SetTDRetry failed"
  35.  
  36. #define RETRY_DEFAULT 10
  37.  
  38. const char *vertag = "$VER: SetTDRetry 37.1 (23.4.94) ©1994 S. Koszewski";
  39.  
  40. // prototypes
  41.  
  42. int PatchUnit(struct ExecBase *SysBase, struct DosLibrary *DOSBase,
  43.               long unit, long quiet, long cnt);
  44. int command(void);
  45.  
  46. // program
  47.  
  48. int command(void)
  49.   {
  50.   struct ExecBase *SysBase = (*((struct ExecBase **)4));
  51.   struct DosLibrary *DOSBase;
  52.   long opts[OPT_COUNT],i,rc = RETURN_FAIL,*units,quiet,cnt;
  53.   struct RDArgs *rdargs;
  54.   
  55.   if(DOSBase = (struct DosLibrary *)OpenLibrary(DOSLIB,DOSVER))
  56.     {
  57.     for(i=0;i<OPT_COUNT;i++) opts[i]=0L;
  58.     rdargs = ReadArgs(TEMPLATE,opts,NULL);
  59.     if(rdargs)
  60.       {
  61.       quiet=opts[OPT_QUIET];
  62.       
  63.       cnt = opts[OPT_RETRY] ? *((long *)opts[OPT_RETRY]) : RETRY_DEFAULT;
  64.         
  65.       if(opts[OPT_UNITS] && cnt>0 && cnt<=100)
  66.         {
  67.         units=(long *)opts[OPT_UNITS];
  68.         while(i = *units++) PatchUnit(SysBase,DOSBase,*((long *)i),quiet,cnt);
  69.         rc = RETURN_OK;
  70.         }
  71.       else rc = RETURN_WARN;
  72.         
  73.       FreeArgs(rdargs);
  74.       }
  75.     else
  76.       PrintFault(IoErr(),MSG_FAILED);
  77.     
  78.     CloseLibrary((struct Library *)DOSBase);
  79.     }
  80.   else
  81.     Result2(ERROR_INVALID_RESIDENT_LIBRARY);
  82.   
  83.   return rc;
  84.   }
  85.  
  86. int PatchUnit(struct ExecBase *SysBase, struct DosLibrary *DOSBase,
  87.               long unit, long quiet, long cnt)
  88.   {
  89.   struct MsgPort *myport;
  90.   struct IORequest *ioreq;
  91.   long rc = RETURN_FAIL;
  92.   
  93.   if(!quiet) VPrintf("Patching trackdisk.device unit #%ld", (APTR)&unit);
  94.   
  95.   if(myport = CreateMsgPort())
  96.     {
  97.     if(ioreq = CreateIORequest(myport,sizeof(struct IORequest)))
  98.       {
  99.       if(!OpenDevice(TD_NAME, unit, ioreq, 0L))
  100.         {
  101.         ((struct TDU_PublicUnit *)ioreq->io_Unit)->tdu_RetryCnt = (UBYTE)cnt;
  102.         rc = RETURN_OK;
  103.         CloseDevice(ioreq);
  104.         }
  105.       DeleteIORequest(ioreq);
  106.       }
  107.     DeleteMsgPort(myport);
  108.     }
  109.   
  110.   if(!quiet) PutStr(rc==RETURN_OK?" - Ok.\n":" - Failed.\n");
  111.   
  112.   return rc;
  113.   }
  114.